package com.fr.report.script.function;

import com.fr.base.core.ComparatorUtils;
import com.fr.report.script.Function;
import com.fr.report.script.Function.Type;
import com.fr.report.script.NormalFunction;
import com.fr.report.script.Primitive;
import com.fr.report.script.core.FArray;

public class INARRAY extends NormalFunction
{
  public Object run(Object[] paramArrayOfObject)
  {
    if (paramArrayOfObject.length != 2)
      return Primitive.ERROR_NAME;
    Object localObject1 = paramArrayOfObject[0];
    Object localObject2 = paramArrayOfObject[1];
    if (!(localObject2 instanceof FArray))
      return Primitive.ERROR_VALUE;
    FArray localFArray = (FArray)localObject2;
    for (int i = 0; i < localFArray.length(); ++i)
      if (ComparatorUtils.equals(localFArray.elementAt(i), localObject1))
        return new Integer(i + 1);
    return new Integer(0);
  }

  public Function.Type getType()
  {
    return Function.ARRAY;
  }

  public String getCN()
  {
    return "INARRAY(co, array):返回co在数组array中的位置，如果co不在array中，则返回0.\n示例：\nString[] arr = {\"a\",\"b\",\"c\",\"d\"}\n那么INARRAY(\"b\", arr)等于2.";
  }

  public String getEN()
  {
    return "INARRAY(co, array):returns the index of co in array, if co isn't contained in array, returns -1.\nExample：\nString[] arr = {\"a\",\"b\",\"c\",\"d\"}\nthen INARRAY(\"b\", arr) returns 1.";
  }
}